package com.example.lock;

import java.util.concurrent.TimeUnit;


class Phone {

	public static synchronized void sendSms() throws Exception {
		TimeUnit.SECONDS.sleep(4);
		System.out.println("---------------sendSms");
	}

	public synchronized void sendEmail() throws Exception {
		System.out.println("---------------sendEmail");
	}

	public void getHello() {
		System.out.println("---------------getHello");
	}
}

public class LockDemo {

	public static void main(String[] args) throws Exception {
		Phone phone = new Phone();
		Phone phone2 = new Phone();

		new Thread(() -> {
			try {
				phone.sendSms();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}, "AA").start();

		Thread.sleep(100);

		new Thread(() -> {
			try {
//				phone.sendEmail();
//				phone.getHello();
				phone2.sendEmail();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}, "BB").start();

	}

}
